$OpenBSD: patch-kdecore_kernel_kstandarddirs_cpp,v 1.3 2014/07/11 11:13:10 zhuk Exp $
1. Provide "libexec" resource type by default, and check for libexec items
   first by default when searching for executables.
2. Use separate from KDE3 links to special resource directories.
3. Use system constants instead of magic values.
--- kdecore/kernel/kstandarddirs.cpp.orig	Sun Jun  8 15:41:32 2014
+++ kdecore/kernel/kstandarddirs.cpp	Fri Jul 11 09:12:18 2014
@@ -285,6 +285,7 @@ QStringList KStandardDirs::allTypes() const
         list.append(QLatin1String(types_string + types_indices[i]));
     // Those are added manually by addKDEDefaults
     list.append(QString::fromLatin1("lib"));
+    list.append(QString::fromLatin1("libexec"));
     //list.append(QString::fromLatin1("home")); // undocumented on purpose, said Waldo in r113855.
 
     // Those are handled by resourceDirs() itself
@@ -479,8 +480,12 @@ QString KStandardDirs::findResource( const char *type,
         filename += QLatin1String(".exe");
     }
 #endif
-    const QString dir = findResourceDir(type, filename);
+    QString dir;
+    if (!strcmp(type, "exe"))
+        dir = findResourceDir("libexec", filename);
     if (dir.isEmpty())
+        dir = findResourceDir(type, filename);
+    if (dir.isEmpty())
       return dir;
     else
       return !KGlobal::hasLocale() ? dir + filename
@@ -1000,14 +1005,13 @@ KStandardDirs::realFilePath(const QString &filename)
 
 void KStandardDirs::KStandardDirsPrivate::createSpecialResource(const char *type)
 {
-    char hostname[256];
-    hostname[0] = 0;
-    gethostname(hostname, 255);
+    char hostname[MAXHOSTNAMELEN];
+    gethostname(hostname, MAXHOSTNAMELEN);
+    hostname[MAXHOSTNAMELEN-1] = 0;
     const QString localkdedir = m_prefixes.first();
-    QString dir = localkdedir + QString::fromLatin1(type) + QLatin1Char('-') + QString::fromLocal8Bit(hostname);
-    char link[1024];
-    link[1023] = 0;
-    int result = readlink(QFile::encodeName(dir).constData(), link, 1023);
+    QString dir = localkdedir + QString::fromLatin1(type) + QLatin1Char('4') + QLatin1Char('-') + QString::fromLocal8Bit(hostname);
+    char link[PATH_MAX+1];
+    int result = readlink(QFile::encodeName(dir).constData(), link, PATH_MAX);
     bool relink = (result == -1) && (errno == ENOENT);
     if (result > 0)
     {
@@ -1051,7 +1055,7 @@ void KStandardDirs::KStandardDirsPrivate::createSpecia
             if (system(QByteArray(QFile::encodeName(srv) + ' ' + type)) == -1) {
                 fprintf(stderr, "Error: unable to launch lnusertemp command" );
             }
-            result = readlink(QFile::encodeName(dir).constData(), link, 1023);
+            result = readlink(QFile::encodeName(dir).constData(), link, PATH_MAX);
         }
     }
     if (result > 0)
@@ -1329,7 +1333,7 @@ QString KStandardDirs::findExe( const QString& appname
                                 const QString& pstr,
                                 SearchOptions options )
 {
-    //kDebug(180) << "findExe(" << appname << ", pstr, " << ignoreExecBit << ") called";
+    kDebug(180) << "findExe(" << appname << ", pstr, " << options << ") called";
 
 #ifdef Q_OS_WIN
     QStringList executable_extensions = executableExtensions();
@@ -1359,7 +1363,7 @@ QString KStandardDirs::findExe( const QString& appname
     QString p = installPath("libexec") + appname;
     QString result = checkExecutable(p, options & IgnoreExecBit);
     if (!result.isEmpty()) {
-        //kDebug(180) << "findExe(): returning " << result;
+        kDebug(180) << "findExe(): returning libexec item " << result;
         return result;
     }
 
@@ -1373,7 +1377,7 @@ QString KStandardDirs::findExe( const QString& appname
         // Check for executable in this tokenized path
         result = checkExecutable(p, options & IgnoreExecBit);
         if (!result.isEmpty()) {
-            //kDebug(180) << "findExe(): returning " << result;
+            kDebug(180) << "findExe(): returning PATH item " << result;
             return result;
         }
     }
@@ -1383,14 +1387,14 @@ QString KStandardDirs::findExe( const QString& appname
     p += appname;
     result = checkExecutable(p, options & IgnoreExecBit);
     if (!result.isEmpty()) {
-        //kDebug(180) << "findExe(): returning " << result;
+        kDebug(180) << "findExe(): returning KDE bin " << result;
         return result;
     }
 
     // If we reach here, the executable wasn't found.
     // So return empty string.
 
-    //kDebug(180) << "findExe(): failed, nothing matched";
+    kDebug(180) << "findExe(): failed, nothing matched";
     return QString();
 }
 
